package com.hc.sp04.order.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import sp01.pojo.Item;
import sp01.pojo.Order;
import sp01.pojo.User;
import sp01.service.OrderService;
import sp01.util.JsonResult;

import java.util.Arrays;

/**
 * @author Z
 * @DATE 2021/8/30 16:17
 * @e-mail ...@qq.com
 */
@RestController
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;

//    获取订单
    @GetMapping("/{orderId}")
    public JsonResult<Order> getOrder(@PathVariable String orderId){
        return JsonResult.ok().data(orderService.getOrder(orderId));
    }

//    添加订单
    @GetMapping("/")
    public JsonResult<?> addOrder(){
        Order order = new Order();
        order.setId("123");
        order.setUser(new User(8,null,null));
        order.setItems(Arrays.asList(new Item[]{
                new Item(1,"商品1",5),
                new Item(2,"商品2",5),
                new Item(3,"商品3",5),
                new Item(4,"商品4",5),
                new Item(5,"商品5",5),
        }));
        orderService.addOrder(order);
        return JsonResult.ok().msg("订单添加成功");
    }
}
